<?php

/**
 * Articulo form.
 *
 * @package    form
 * @subpackage articulo
 * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class ArticuloForm extends BaseArticuloForm
{
  public function configure()
  {
  	$this->widgetSchema['foto'] = new sfWidgetFormInputFile();
  	$this->validatorSchema['foto']= new sfValidatorFile(array('required'=>false));
  	$this->validatorSchema['codigo'] = new sfValidatorString(array('max_length' => 20, 'required' => true));
  }
  
  public function updateObject($values = null)
  {
  	$objeto = parent::updateObject();
  	$foto = $objeto->getFoto();
  	if(is_object($this->getValue('foto')))
  	 $objeto->setFoto(str_replace(sfConfig::get('sf_root_dir').'/web/images/fotos/', '', $objeto->getFoto()));
  	else
  	{
  	  if ($objeto->isNew())
  	     $objeto->setFoto('none.png');
  	  else
  	  {
  	     $objeto->setFoto(ArticuloPeer::retrieveByPK($objeto->getId())->getFoto());
  	  }
  	}
  	return $objeto;
  }
  
  
}
